#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

PainterWidget::PainterWidget(QWidget *parent):QWidget (parent)
{

}

PainterWidget::~PainterWidget()
{
    resize(500,500);
}

void PainterWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    //设置抗锯齿
    painter.setRenderHint(QPainter::Antialiasing,true);
    //设置笔颜色
    QPen pen(Qt::cyan);
    pen.setWidth(2);
    painter.setPen(pen);
    //绘制
    painter.drawRect(50,50,100,100);
    //椭圆
    painter.setBrush(QBrush(Qt::green));
    painter.drawEllipse(200,50,100,100);
    //线条
    painter.setPen(QPen(Qt::blue,3));
    painter.drawLine(50,200,350,200);

    //text
    painter.setPen(QPen(Qt::yellow));
    painter.setFont(QFont("Arial",16));
    painter.drawText(150,250,"Hello QT");


}





